<template>
  <BasicModal :show="show" title="入职" width="30%" :widthComfirm="true" @comfirm="comfirm" @closeModal="closeModal">
    <template #content>
      <CommonForm v-if="show" :formList="formList" ref="formRef"></CommonForm>
    </template>
  </BasicModal>
</template>

<script setup lang='ts'>
import { ref, watch } from "vue"
import CommonForm from "@/views/applicationDetails/CommonForm.vue";
import BasicModal from "./BasicModal.vue";
import { message } from "ant-design-vue";
import {
  onBoardingProgress
  , selectCommonConfigDetail, selectUserByRole,
  secondInterview, getEntrySchoolInfo, selectCommonConfigFoChildren
} from "@/api/application-details/index.ts";


import { comStores } from '@/store/common/comStore';
import { IndexFormItem } from "../../applicationDetails/application-type";
const store = comStores()

interface Options {
  label: string;
  value?: string | number
}
const props = defineProps(['param'])
const show = ref<boolean>(false);
const paramsList = () => ([
  { label: "入职", name: "cascader", value: [], component: 'cascader', options: [] },
  { label: "导师", name: "entryTeacher", value: "", component: 'select', options: [] },
  { label: "备注", name: "remark", value: "", component: 'textarea', required: false },
])
const formList = ref<IndexFormItem[]>(paramsList())

watch(() => show.value, (val) => {
  if (val) {
    getOptions()
  }
})

const getOptions = async () => {
  const { resumeId } = store.currentResume;
  const teacher = await selectUserByRole("MENTOR") //导师
  const subject = await selectCommonConfigFoChildren({ type: 1 }) //科目
  let info = await getEntrySchoolInfo({ resumeId, type: 0 });
  if (info.data) {
    const { school, subject, grade } = info.data
    formList.value[0].value = [school, subject, grade] as any
  }
  formList.value[0].options = subject.data
  formList.value[1].options = teacher.data
}
const emits = defineEmits(['onSuccess'])
const formRef = ref<any>(null)
const comfirm = async () => {
  const res = await formRef.value.submitForm();
  if (!res) return;
  let param: any = {}
  res.forEach(el => {
    param[el.name] = el.value
  });
  console.log(param)
  param.resumeId = info.value.id
  param.processId = info.value.processId;
  param.operator = info.value.operator;
  param.result = "通过";
  param.entrySchool = param.cascader[0]
  param.entryUnit = param.cascader[1];
  param.entryPosition = param.cascader[2];
  let data: any = {}
  data = await onBoardingProgress(param);
  if (data && data.code === '10000') {
    message.success("操作成功");
    emits('onSuccess')
    formList.value = paramsList()
    show.value = false
  } else {
    message.error(data.msg)
  }
}
const info = ref<any>({});
const open = (params: any) => {
  
  info.value = params.info
  const { entryLocation, entrySubject, entryGrade } = params.info
  formList.value[0].value = [entryLocation, entrySubject, entryGrade]
  show.value = true
}
const closeModal = () => {
  show.value = false
  formList.value = paramsList()
  formRef.value.clear()
}
defineExpose({ open })
</script>

<style lang="less" scoped>
.progress {
  display: flex;
  justify-content: end;
  margin: 24px 0;
  padding-top: 24px;
  ;
  font-weight: 400;
  font-size: 14px;
  color: #333333;

  .desc {

    font-weight: 400;
    font-size: 14px;
    color: #209EE4;

  }
}
</style>
